package com.letoken.platform.repo.ecommerce.dao;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.letoken.platform.pub.req.PageData;
import com.letoken.platform.repo.app.req.mall.CollectShopsReq;
import com.letoken.platform.repo.app.res.mall.MallCollectShopsRes;
import com.letoken.platform.repo.ecommerce.dto.ShopFreightTemplateReq;
import com.letoken.platform.repo.ecommerce.po.EcommerceFreightTemplate;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.letoken.platform.repo.ecommerce.po.EcommerceUserAddress;
import com.letoken.platform.repo.ecommerce.vo.ShippingCalculateVo;
import com.letoken.platform.repo.ecommerce.vo.ShopFreightTemplateRes;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.web3j.abi.datatypes.Int;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 店铺运费模板 Mapper 接口
 * </p>
 *
 * @author author
 * @since 2023-11-20
 */
public interface EcommerceFreightTemplateMapper extends BaseMapper<EcommerceFreightTemplate> {

    Page<ShopFreightTemplateRes> templateList(@Param("page") Page<ShopFreightTemplateRes> page , @Param("req") ShopFreightTemplateReq req);


    @Select("select * from ecommerce_freight_template where id = #{id} and mall_id = #{mallId} and delete_status = 0 limit 1")
    EcommerceFreightTemplate isExits(@Param("id") Integer id , @Param("mallId") Integer mallId);


    @Select("select t.* from ecommerce_freight_template t inner join ecommerce_product_detail d on t.id = d.template_id where d.id = #{productId} ")
    ShippingCalculateVo templateInfo(@Param("productId") Integer productId);


    @Select("select d.id as productId,t.id as templateId from  ecommerce_product_detail d inner join ecommerce_freight_template t on t.id = d.template_id where d.id in (${ids}) ")
    List<Map<String,Integer>> templateMapperProductId(@Param("ids") String ids);


    @Select("select 1 from  ecommerce_product_detail d where d.id in  (${ids}) and   (ISNULL(d.template_id) or d.template_id <= 0)  limit 1 ")
    Integer existNullTemplate(@Param("ids") String ids);


    @Select("select 1 from  app_mall_info d where d.id in  (${ids}) and   (ISNULL(d.shipping_type) or d.shipping_type <= 0)  limit 1 ")
    Integer existNullShippingType(@Param("ids") String ids);

    @Select("select p.publish_status from ecommerce_product_detail d,ecommerce_product p,ecommerce_freight_template t where t.id=d.template_id and p.id=d.id and d.template_id=#{templateId} and p.publish_status=0")
    List<Integer> getTemplateByStatus(@Param("templateId")Integer templateId);

}
